package JUC.AtomicLeiAPI;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntUnaryOperator;

/**
 * @author CKC
 * @DateTime 2021/6/3 16:44
 */
public class AtomicInteger1 {
    
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(10);
        
        atomicInteger.getAndIncrement();//i++  先获取在自增
        atomicInteger.incrementAndGet();//++i  先自增在获取
        
        atomicInteger.decrementAndGet();//--i
        atomicInteger.getAndDecrement();//i--
        
        
        System.out.println(atomicInteger.addAndGet(10));//  先加上10 在获取
        
        int i = atomicInteger.updateAndGet(x -> x * x);//IntUnaryOperator  函数式接口
        System.out.println(i);
        
        System.out.println("------------------------------------------");
        
        System.out.println(((IntUnaryOperator) operand -> operand * operand).applyAsInt(10));
        
        
    }
}
